package james.timer;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;


public class TimerTest {

    public static void main(String[] args) {

        try {
        	
        	System.out.println("new schedule");
        	System.out.println("test");
        	System.out.println("no extra debugging");
        	
            // Grab the Scheduler instance from the Factory 
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

            // and start it off
            scheduler.start();

            
            DefaultScheduledTask task1 = new DefaultScheduledTask();
            task1.setRepeatInterval(20);
            task1.setLabel("task1");
            DefaultScheduledTask task2 = new DefaultScheduledTask();
            task2.setRepeatInterval(15);
            task2.setLabel("task2");
            
            System.out.println("jobs");
            /**
            // define the job and tie it to our HelloJob class
            JobDetail job1 = JobBuilder.newJob(DefaultScheduledTask.class)
                .withIdentity("job1", "group1")
                .build();
            job1.getJobDataMap().put("label", task1);

            JobDetail job2 = JobBuilder.newJob(DefaultScheduledTask.class)
                    .withIdentity("job2", "group2")
                    .build();
                job2.getJobDataMap().put("label", task2);

                            
            
                System.out.println("triggers");
            // Trigger the job to run now, and then repeat every 40 seconds
            Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds((int)task1.getRepeatInterval())
                        .repeatForever())            
                .build();

            // Tell quartz to schedule the job using our trigger
            scheduler.scheduleJob(job1, trigger);
            
         // Trigger the job to run now, and then repeat every 40 seconds
            Trigger trigger2 = TriggerBuilder.newTrigger()
                .withIdentity("trigger2", "group2")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds((int)task2.getRepeatInterval())
                        .repeatForever())            
                .build();

            // Tell quartz to schedule the job using our trigger
            scheduler.scheduleJob(job2, trigger2);
**/
            //scheduler.shutdown();

        } catch (SchedulerException se) {
            se.printStackTrace();
        }
    }
}